package com.qi.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qi.common.RoleKey;
import com.qi.pojo.dto.ApplyClubBody;
import com.qi.pojo.entity.AppProcess;
import com.qi.pojo.vo.AjaxResult;
import com.qi.services.IAppProcessService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/apply")
@Tag(name = "社团申请管理")
public class AppProcessController {

    @Resource
    private IAppProcessService appProcessService;

    @SaCheckRole(RoleKey.游客)
    @Operation(summary = "申请加入社团")
    @PostMapping("/apply")
    public AjaxResult apply(@RequestBody ApplyClubBody applyClubBody) {
        appProcessService.apply(applyClubBody);
        return AjaxResult.ok("申请成功，等待社长审核");
    }

    @SaCheckRole(RoleKey.社团管理员)
    @Operation(summary = "查询社长所有申请记录")
    @GetMapping("/getList/{current}/{size}")
    public AjaxResult getList(@PathVariable("current") Long current,
                              @PathVariable("size") Long size) {

        IPage<AppProcess> appProcessPage = appProcessService.getList(current, size);
        return AjaxResult.success(appProcessPage);
    }

    @SaCheckRole(RoleKey.社团管理员)
    @Operation(summary = "查询社长待办申请")
    @GetMapping("/getPendingApprovalList/{current}/{size}")
    public AjaxResult getPendingApprovalList(@PathVariable("current") Long current,
                                             @PathVariable("size") Long size) {

        IPage<AppProcess> pendingApprovalList = appProcessService.getPendingApprovalList(current, size);
        return AjaxResult.success(pendingApprovalList);
    }

    @SaCheckRole(RoleKey.社团管理员)
    @Operation(summary = "批准加入社团")
    @GetMapping("/approval/{id}/{userId}/{clubId}")
    public AjaxResult approval(@PathVariable("id") Long id,
                               @PathVariable("userId") Long userId,
                               @PathVariable("clubId") Long clubId) {

        appProcessService.approval(id, userId, clubId);
        return AjaxResult.success();
    }

    @SaCheckRole(RoleKey.社团管理员)
    @Operation(summary = "拒绝加入社团")
    @GetMapping("/reject/{id}/{userId}/{clubId}")
    public AjaxResult reject(@PathVariable("id") Long id,
                             @PathVariable("userId") Long userId,
                             @PathVariable("clubId") Long clubId) {

        appProcessService.reject(id, userId, clubId);
        return AjaxResult.success();
    }
}
